<?php
/**
 * @package YARBB
 * @copyright Авторские права (C) 2009 www.yar-it.com. Все права защищены.
 * @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
 * YARBB! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
 * Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл copyright.php.
 */
// don't allow direct linking
defined( '_VALID_MOS' ) or die();


// This particular function doesn't require forum-based moderator access. It can be used
// by all moderators and admins.
if (isset($_GET['get_host'])) {
	if ($yarbb_user['g_id'] > YARBB_MOD && !$yarbb_user['g_global_moderation'])
		mosRedirect(sefRelToAbs(YARBB_URL), _NOT_AUTH);
	// Is get_host an IP address or a post ID?
	if (preg_match('/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/', $_GET['get_host']))
		$ip = $_GET['get_host'];
	else {
		$get_host = intval($_GET['get_host']);
		if ($get_host < 1)
			mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
		$result = $database->setQuery('SELECT poster_ip FROM #__forum_posts WHERE id='.$get_host);
		$database->query();
		if (!$database->getNumRows())
			mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
		$ip = $database->loadResult();
	}
	message('The IP address is: '.$ip.'<br />The host name is: '.@gethostbyaddr($ip).'<br /><br /><a href="'.sefRelToAbs(YARBB_URL.'&amp;task=admin_users&amp;show_users='.$ip).'">Show more users for this IP</a>');
}
// All other functions require moderator/admin access
$fid = isset($_GET['fid']) ? intval($_GET['fid']) : 0;
if ($fid < 1)
	mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
$sql = ('SELECT moderators FROM #__forum_forums WHERE id='.$fid);
$moderators = $database->setQuery($sql)->loadResult();
$mods_array = ($moderators != '') ? unserialize($moderators) : array();
if ($yarbb_user['g_id'] != YARBB_ADMIN && ($yarbb_user['g_id'] != YARBB_MOD || !array_key_exists($yarbb_user['username'], $mods_array)) && (!$yarbb_user['g_global_moderation']))
	mosRedirect(sefRelToAbs(YARBB_URL), _NOT_AUTH);

// All other topic moderation features require a topic id in GET
if (isset($_GET['tid'])) {
	$tid = intval($_GET['tid']);
	if ($tid < 1)
		mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
	// Fetch some info about the topic
	$database->setQuery('SELECT t.subject, t.num_replies, f.id AS forum_id, forum_name FROM #__forum_topics AS t INNER JOIN #__forum_forums AS f ON f.id=t.forum_id LEFT JOIN #__forum_subscriptions AS s ON (t.id=s.topic_id AND s.user_id='.$yarbb_user['id'].') LEFT JOIN #__forum_forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$yarbb_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$fid.' AND t.id='.$tid.' AND t.moved_to IS NULL');
	$database->query();
	if (!$database->getNumRows())
		mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
	$rows=$database->loadAssocList();
	$cur_topic =$rows[0];// $db->fetch_assoc($result);

	// Delete one or more posts
	if (isset($_POST['delete_posts']) || isset($_POST['delete_posts_comply'])) {
		$posts = $_POST['posts'];
		if (empty($posts))
			mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=viewtopic&amp;id='.$tid), _Y_YAMODNOPOST);
		if (isset($_POST['delete_posts_comply'])) {
			//confirm_referrer('moderate.php');
			if (preg_match('/[^0-9,]/', $posts))
				mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);

			// Delete the posts
			//s
			$database->setQuery('DELETE FROM #__forum_posts WHERE id IN('.$posts.')');
			$database->query();
			require $yarbb_admin_path.'/include/search_idx.php';
			strip_search_index($posts);

			// Get last_post, last_post_id, and last_poster for the topic after deletion
			//s
			$sql = ('SELECT id, poster, posted FROM #__forum_posts WHERE topic_id='.$tid.' ORDER BY id DESC LIMIT 1');
			$rows=$database->setQuery($sql)->loadAssocList();
			$last_post = $rows[0];//$db->fetch_assoc($result);

			// How many posts did we just delete?
			$num_posts_deleted = substr_count($posts, ',') + 1;

			// Update the topic
			$database->setQuery('UPDATE #__forum_topics SET last_post='.$last_post['posted'].', last_post_id='.$last_post['id'].', last_poster=\''.$database->getEscaped($last_post['poster']).'\', num_replies=num_replies-'.$num_posts_deleted.' WHERE id='.$tid) ;
			$database->query();
			update_forum($fid);
			mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=viewtopic&amp;id='.$tid), _SUCCESS_DELETION);
		}
		echo $mainframe->setPageTitle( _Y_YARMODERS.' - '.yarbb_htmlspecialchars($yarbb_config['o_board_title']));
		?>

<div class="blockform">
	<h2><span><?php echo _Y_YARMODDELPOST; ?></span></h2>
	<div class="box">
		<form method="post" action="<?php echo YARBB_URL; ?>&amp;task=moderate&amp;fid=<?php echo $fid ?>&amp;tid=<?php echo $tid ?>">
			<div class="inform">
				<fieldset>
					<legend><?php echo _Y_CATDELAVT; ?></legend>
					<div class="infldset">
						<input type="hidden" name="posts" value="<?php echo implode(',', array_keys($posts)) ?>" />
						<p><?php echo _Y_YAMODPOSTDEL; ?></p>
					</div>
				</fieldset>
			</div>
			<input type="submit" name="delete_posts_comply" value="<?php echo _E_REMOVE; ?>" />
			<input name="" type="button" onclick="javascript:history.go(-1)" value="<?php echo _BUTTON_CANCEL; ?>" />
		</form>
	</div>
</div>
		<?php
	}
	// Show the delete multiple posts view
	// Used to disable the Move and Delete buttons if there are no replies to this topic
	$button_status = ($cur_topic['num_replies'] == 0) ? ' disabled' : '';
	// Determine the post offset (based on $_GET['p'])
	$num_pages = ceil(($cur_topic['num_replies'] + 1) / $yarbb_user['disp_posts']);
	$p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : $_GET['p'];
	$start_from = $yarbb_user['disp_posts'] * ($p - 1);
	// Generate paging links
	$paging_links = _PN_PAGE.': '.paginate($num_pages, $p, YARBB_URL.'&amp;task=moderate&amp;fid='.$fid.'&amp;tid='.$tid);
	if ($yarbb_config['o_censoring'] == '1')
		$cur_topic['subject'] = censor_words($cur_topic['subject']);
	echo $mainframe->setPageTitle( yarbb_htmlspecialchars($yarbb_config['o_board_title']).' - '.$cur_topic['subject']);
	?>
<div class="linkst">
	<div class="inbox">
		<p class="pagelink conl"><?php echo $paging_links ?></p>
		<ul>
			<li><a href="<?php echo sefRelToAbs(YARBB_URL) ?>"><?php echo _Y_INDEX; ?></a></li>
			<li>&nbsp;&raquo;&nbsp;<a href="<?php echo sefRelToAbs(YARBB_URL.'&amp;task=viewforum&amp;id='.$fid); ?>"><?php echo yarbb_htmlspecialchars($cur_topic['forum_name']) ?></a></li>
			<li>&nbsp;&raquo;&nbsp;<?php echo yarbb_htmlspecialchars($cur_topic['subject']) ?></li>
		</ul>
		<div class="clearer"></div>
	</div>
</div>
<form method="post" action="<?php echo YARBB_URL; ?>&amp;task=moderate&amp;fid=<?php echo $fid; ?>&amp;tid=<?php echo $tid; ?>">
	<?php
	require $yarbb_path.'/inc/parser.php';
	$bg_switch = true;	// Used for switching background color in posts
		$post_count = 0;	// Keep track of post numbers
		// Retrieve the posts (and their respective poster)
		//s
		$sql = ('SELECT u.title, u.num_posts, g.g_id, g.g_user_title, p.id, p.poster, p.poster_id, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by FROM #__forum_posts AS p INNER JOIN #__forum_users AS u ON u.id=p.poster_id INNER JOIN #__forum_groups AS g ON g.g_id=u.group_id WHERE p.topic_id='.$tid.' ORDER BY p.id LIMIT '.$start_from.','.$yarbb_user['disp_posts']);
		$rows = $database->setQuery($sql)->loadAssocList();

		foreach ($rows as $cur_post ) {
			$post_count++;
			// If the poster is a registered user.
			if ($cur_post['poster_id'] > 1) {
				$poster = '<a href="'.sefRelToAbs('index.php?option=com_users&task=profile&amp;user='.$cur_post['poster_id']).'">'.yarbb_htmlspecialchars($cur_post['poster']).'</a>';
				// get_title() requires that an element 'username' be present in the array
				$cur_post['username'] = $cur_post['poster'];
				$user_title = get_title($cur_post);
				if ($yarbb_config['o_censoring'] == '1')
					$user_title = censor_words($user_title);
			}
			// If the poster is a guest (or a user that has been deleted)
			else {
				$poster = yarbb_htmlspecialchars($cur_post['poster']);
				$user_title = _Y_YARGUEST;
			}
			// Switch the background color for every message.
			$bg_switch = ($bg_switch) ? $bg_switch = false : $bg_switch = true;
			$vtbg = ($bg_switch) ? ' roweven' : ' rowodd';
			// Perform the main parsing of the message (BBCode, smilies, censor words etc)
			$cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
			?>
	<div class="blockpost<?php echo $vtbg ?>"> <a name="<?php echo $cur_post['id'] ?>"></a>
		<h2><span><span class="conr">#<?php echo ($start_from + $post_count) ?>&nbsp;</span><a href="<?php echo sefRelToAbs(YARBB_URL.'&amp;task=viewtopic&amp;pid='.$cur_post['id']).'#p'.$cur_post['id']; ?>"><?php echo format_time($cur_post['posted']) ?></a></span></h2>
		<div class="box">
			<div class="inbox">
				<div class="postleft">
					<dl>
						<dt><strong><?php echo $poster ?></strong></dt>
						<dd><strong><?php echo $user_title ?></strong></dd>
					</dl>
				</div>
				<div class="postright">
					<h3 class="nosize"><?php echo _Y_MESSAGE; ?></h3>
					<div class="postmsg"> <?php echo $cur_post['message']."\n" ?>
		<?php if ($cur_post['edited'] != '') echo "\t\t\t\t\t".'<p class="postedit"><em>'._Y_YARLASTEDIT.''.yarbb_htmlspecialchars($cur_post['edited_by']).' ('.format_time($cur_post['edited']).')</em></p>'."\n"; ?>
					</div>
		<?php if ($start_from + $post_count > 1) echo '<p class="multidelete"><label><strong>'._SELECT.'</strong>&nbsp;&nbsp;<input type="checkbox" name="posts['.$cur_post['id'].']" value="1" /></label></p>'."\n" ?>
				</div>
				<div class="clearer"></div>
			</div>
		</div>
	</div>
							<?php
	}
	?>
	<div class="postlinksb">
		<div class="inbox">
			<p class="pagelink conl"><?php echo $paging_links ?></p>
			<p class="conr">
				<input type="submit" name="delete_posts" value="<?php echo _E_REMOVE; ?>"<?php echo $button_status ?> />
			</p>
			<div class="clearer"></div>
		</div>
	</div>
</form>
	<?php
	require $yarbb_path.'/task/footer.php';
}
else if (isset($_REQUEST['move_topics']) || isset($_POST['move_topics_to'])) {
	if (isset($_POST['move_topics_to'])) {
		if (preg_match('/[^0-9,]/', $_POST['topics']))
			mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
		$topics = explode(',', $_POST['topics']);
		$move_to_forum = isset($_POST['move_to_forum']) ? intval($_POST['move_to_forum']) : 0;
		if (empty($topics) || $move_to_forum < 1)
			mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);

		// Delete any redirect topics if there are any (only if we moved/copied the topic back to where it where it was once moved from)
		$database->setQuery('DELETE FROM #__forum_topics WHERE forum_id='.$move_to_forum.' AND moved_to IN('.implode(',',$topics).')');
		$database->query();

		// Move the topic(s)
		$database->setQuery('UPDATE #__forum_topics SET forum_id='.$move_to_forum.' WHERE id IN('.implode(',',$topics).')');
		$database->query();

		// Should we create redirect topics?
		if (isset($_POST['with_redirect'])) {
			while (list(, $cur_topic) = @each($topics)) {
				// Fetch info for the redirect topic
				$sql = ('SELECT poster, subject, posted, last_post FROM #__forum_topics WHERE id='.$cur_topic);
				$rows=$database->setQuery($sql)->loadAssocList();
				$moved_to = $rows[0];//s$db->fetch_assoc($result);

				// Create the redirect topic
				$database->setQuery('INSERT INTO #__forum_topics (poster, subject, posted, last_post, moved_to, forum_id) VALUES(\''.$database->getEscaped($moved_to['poster']).'\', \''.$database->getEscaped($moved_to['subject']).'\', '.$moved_to['posted'].', '.$moved_to['last_post'].', '.$cur_topic.', '.$fid.')');
				$database->query();
			}
		}
		update_forum($fid);				// Update the forum FROM which the topic was moved
		update_forum($move_to_forum);	// Update the forum TO which the topic was moved
		mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=viewforum&amp;id='.$move_to_forum), _Y_YAMOMOVES);
	}
	if (isset($_POST['move_topics'])) {
		$topics = isset($_POST['topics']) ? $_POST['topics'] : array();
		if (empty($topics))
			mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=viewforum&amp;id='.$fid), _Y_YAMODNOPOST2);
		$topics = implode(',', array_keys($topics));
		$action = 'multi';
	}
	else {
		$topics = intval($_GET['move_topics']);
		if ($topics < 1)
			mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
		$action = 'single';
	}
	echo $mainframe->setPageTitle( yarbb_htmlspecialchars($yarbb_config['o_board_title']).' - '._Y_YARMODERS );
	?>
<div class="blockform">
	<h2><span><?php echo _Y_YAMOVETOP; ?></span></h2>
	<div class="box">
		<form method="post" action="<?php echo YARBB_URL; ?>&amp;task=moderate&amp;fid=<?php echo $fid; ?>">
			<div class="inform">
				<input type="hidden" name="topics" value="<?php echo $topics ?>" />
				<fieldset>
					<legend><?php echo _Y_YASELFOR; ?></legend>
					<div class="infldset">
						<label><?php echo _JWMM_MOVE_TO;?> <br />
							<select name="move_to_forum">
	<?php
	//s
	$result = $database->setQuery('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name FROM #__forum_categories AS c INNER JOIN #__forum_forums AS f ON c.id=f.cat_id LEFT JOIN #__forum_forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$yarbb_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position', true);
	$cur_category = 0;
	$rows=$database->loadAssocList();

	foreach ($rows as $cur_forum ) {
		if ($cur_forum['cid'] != $cur_category)	// A new category since last iteration?
		{
			if ($cur_category)
				echo "\t\t\t\t\t\t\t".'</optgroup>'."\n";
			echo "\t\t\t\t\t\t\t".'<optgroup label="'.yarbb_htmlspecialchars($cur_forum['cat_name']).'">'."\n";
											$cur_category = $cur_forum['cid'];
										}
										if ($cur_forum['fid'] != $fid)
											echo "\t\t\t\t\t\t\t\t".'<option value="'.$cur_forum['fid'].'">'.yarbb_htmlspecialchars($cur_forum['forum_name']).'</option>'."\n";
									}
									?>
								</optgroup>
							</select>
							<br />
						</label>
						<div class="rbox">
							<label>
								<input type="checkbox" name="with_redirect" value="1"<?php if ($action == 'single') echo ' checked="checked"' ?> />
									<?php echo _Y_YARREDIRTOP; ?><br />
							</label>
						</div>
					</div>
				</fieldset>
			</div>
			<input type="submit" name="move_topics_to" value="<?php echo _Y_YAR_MOVE; ?>" />
			<input name="" type="button" onclick="javascript:history.go(-1)" value="<?php echo _BUTTON_CANCEL; ?>" />
		</form>
	</div>
</div>
	<?php
	require $yarbb_path.'/task/footer.php';
								}
// Delete one or more topics
else if (isset($_REQUEST['delete_topics']) || isset($_POST['delete_topics_comply'])) {
	$topics = isset($_POST['topics']) ? $_POST['topics'] : array();
	if (empty($topics))
		mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=viewforum&amp;id='.$fid), _Y_YAMODNOPOST2);
	if (isset($_POST['delete_topics_comply'])) {
		//confirm_referrer('moderate.php');
		if (preg_match('/[^0-9,]/', $topics))
			mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
		require $yarbb_admin_path.'/include/search_idx.php';
		// Delete the topics and any redirect topics
		$database->setQuery('DELETE FROM #__forum_topics WHERE id IN('.$topics.') OR moved_to IN('.$topics.')');
		$database->query();
		// Delete any subscriptions
		$database->setQuery('DELETE FROM #__forum_subscriptions WHERE topic_id IN('.$topics.')');
		$database->query();
		// Create a list of the post ID's in this topic and then strip the search index
		$database->setQuery('SELECT id FROM #__forum_posts WHERE topic_id IN('.$topics.')');

		$post_ids = '';
		//s
		$rows=$database->loadRowList();
		foreach ($rows as $row)
			$post_ids .= ($post_ids != '') ? ','.$row[0] : $row[0];
		// We have to check that we actually have a list of post ID's since we could be deleting just a redirect topic
		if ($post_ids != '')
			strip_search_index($post_ids);
		// Delete posts
		$database->setQuery('DELETE FROM #__forum_posts WHERE topic_id IN('.$topics.')');
		$database->query();
		update_forum($fid);
		mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=viewforum&amp;id='.$fid), _SUCCESS_DELETION);
	}
	echo $mainframe->setPageTitle( _Y_YARMODERS );
	?>
<div class="blockform">
	<h2><?php echo _DELETING; ?></h2>
	<div class="box">
		<form method="post" action="<?php echo YARBB_URL; ?>&amp;task=moderate&amp;fid=<?php echo $fid; ?>">
			<input type="hidden" name="topics" value="<?php echo implode(',', array_keys($topics)) ?>" />
			<div class="inform">
				<fieldset>
					<legend><?php echo _Y_CATDELAVT; ?></legend>
					<div class="infldset">
						<p><?php echo _Y_YAMODPOSTDEL2; ?></p>
					</div>
				</fieldset>
			</div>
			<input type="submit" name="delete_topics_comply" value="<?php echo _E_REMOVE; ?>" />
			<input name="" type="button" onclick="javascript:history.go(-1)" value="<?php echo _CANCEL; ?>" />
		</form>
	</div>
</div>
	<?php
	require $yarbb_path.'/task/footer.php';
}
// Open or close one or more topics
else if (isset($_REQUEST['open']) || isset($_REQUEST['close'])) {
	$action = (isset($_REQUEST['open'])) ? 0 : 1;
	// There could be an array of topic ID's in $_POST
	if (isset($_POST['open']) || isset($_POST['close'])) {
		$topics = isset($_POST['topics']) ? @array_map('intval', @array_keys($_POST['topics'])) : array();
		if (empty($topics))
			mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=viewforum&amp;id='.$fid), _Y_YAMODNOPOST2);
		$database->setQuery('UPDATE #__forum_topics SET closed='.$action.' WHERE id IN('.implode(',', $topics).')');
		$database->query();
		$redirect_msg = ($action) ? _Y_YACLOSTOP : _Y_YAOPENTOPS;
		mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=moderate&amp;fid='.$fid), $redirect_msg);
	}
	// Or just one in $_GET
	else {
		//confirm_referrer('index.php?option=com_forum&amp;task=viewtopic');
		$topic_id = ($action) ? intval($_GET['close']) : intval($_GET['open']);
		if ($topic_id < 1)
			mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
		$database->setQuery('UPDATE #__forum_topics SET closed='.$action.' WHERE id='.$topic_id);
		$database->query();
		$redirect_msg = ($action) ? _Y_YACLOSTOP : _Y_YAOPENTOPS;
		mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=viewtopic&amp;id='.$topic_id), $redirect_msg);
	}
}
// Stick a topic
else if (isset($_GET['stick'])) {

	$stick = intval($_GET['stick']);
	if ($stick < 1)
		mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
	$database->setQuery('UPDATE #__forum_topics SET sticky=\'1\' WHERE id='.$stick);
	$database->query();
	mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=viewtopic&amp;id='.$stick), _Y_YASTICKY);
}
// Unstick a topic
else if (isset($_GET['unstick'])) {

	$unstick = intval($_GET['unstick']);
	if ($unstick < 1)
		mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
	$database->setQuery('UPDATE #__forum_topics SET sticky=\'0\' WHERE id='.$unstick);
	$database->query();
	mosRedirect(sefRelToAbs(YARBB_URL.'&amp;task=viewtopic&amp;id='.$unstick), _Y_YAUNSTIKS);
} else {
// No specific forum moderation action was specified in the query string, so we'll display the moderator forum

// Fetch some info about the forum
//s
	$result = $database->setQuery('SELECT f.forum_name, f.redirect_url, f.num_topics FROM #__forum_forums AS f LEFT JOIN #__forum_forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$yarbb_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$fid);
	$database->query();
	if (!$database->getNumRows())
		mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);
	$rows=$database->loadAssocList();

	$cur_forum = $rows[0];//$db->fetch_assoc($result);
// Is this a redirect forum? In that case, abort!
	if ($cur_forum['redirect_url'] != '')
		mosRedirect(sefRelToAbs(YARBB_URL), _Y_404);

	echo $mainframe->setPageTitle( _Y_YARMODERS.' - '.yarbb_htmlspecialchars($cur_forum['forum_name']) );

// Determine the topic offset (based on $_GET['p'])
	$num_pages = ceil($cur_forum['num_topics'] / $yarbb_user['disp_topics']);
	$p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : $_GET['p'];
	$start_from = $yarbb_user['disp_topics'] * ($p - 1);
// Generate paging links
	$paging_links = _PN_PAGE.': '.paginate($num_pages, $p, YARBB_URL.'&amp;task=moderate&amp;fid='.$fid);
	?>
<div class="linkst">
	<div class="inbox">
		<p class="pagelink conl"><?php echo $paging_links ?></p>
		<ul>
			<li><a href="<?php echo sefRelToAbs(YARBB_URL) ?>"><?php echo _Y_INDEX; ?></a>&nbsp;</li>
			<li>&raquo;&nbsp;<?php echo yarbb_htmlspecialchars($cur_forum['forum_name']) ?></li>
		</ul>
		<div class="clearer"></div>
	</div>
</div>
<form method="post" action="<?php echo YARBB_URL; ?>&amp;task=moderate&amp;fid=<?php echo $fid ?>">
	<div id="vf" class="blocktable">
		<h2><span><?php echo yarbb_htmlspecialchars($cur_forum['forum_name']) ?></span></h2>
		<div class="box">
			<div class="inbox">
				<table cellspacing="0">
					<thead>
						<tr>
							<th class="tcl" scope="col"><?php echo _Y_TOPICS; ?></th>
							<th class="tc2" scope="col"><?php echo _Y_REPLYSY; ?></th>
							<th class="tc3" scope="col"><?php echo _Y_YARVIEWTOP; ?></th>
							<th class="tcr"><?php echo _Y_LASTPOST; ?></th>
							<th class="tcmod" scope="col"></th>
						</tr>
					</thead>
					<tbody>
	<?php
// Select topics
	$result = $database->setQuery('SELECT id, poster, subject, posted, last_post, last_post_id, last_poster, num_views, num_replies, closed, sticky, moved_to FROM #__forum_topics WHERE forum_id='.$fid.' ORDER BY sticky DESC, last_post DESC LIMIT '.$start_from.', '.$yarbb_user['disp_topics']);
	$database->query();
// If there are topics in this forum.
	if ($database->getNumRows()) {
		$button_status = '';
		$rows=$database->loadAssocList();

		foreach ($rows as $cur_topic ) {

			$item_status = '';
			$icon_type = 'icon';
			if ($cur_topic['moved_to'] == null) {
				$last_post = '<a href="'.sefRelToAbs(YARBB_URL.'&amp;task=viewtopic&amp;pid='.$cur_topic['last_post_id']).'#p'.$cur_topic['last_post_id'].'">'.format_time($cur_topic['last_post']).'</a> '._Y_YARBY.' '.yarbb_htmlspecialchars($cur_topic['last_poster']);
				$ghost_topic = false;
			}
			else {
				$last_post = '&nbsp;';
				$ghost_topic = true;
			}
									if ($yarbb_config['o_censoring'] == '1')
										$cur_topic['subject'] = censor_words($cur_topic['subject']);
									if ($cur_topic['moved_to'] != 0)
										$subject = _Y_FRONTMOVED.': <a href="'.sefRelToAbs(YARBB_URL.'&amp;task=viewtopic&amp;id='.$cur_topic['moved_to']).'">'.yarbb_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'._Y_YARBY.' '.yarbb_htmlspecialchars($cur_topic['poster']).'</span>';
									else if ($cur_topic['closed'] == '0')
										$subject = '<a href="'.sefRelToAbs(YARBB_URL.'&amp;task=viewtopic&amp;id='.$cur_topic['id']).'">'.yarbb_htmlspecialchars($cur_topic['subject']).'</a> <span>'._Y_YARBY.'&nbsp;'.yarbb_htmlspecialchars($cur_topic['poster']).'</span>';
									else {
										$subject = '<a href="'.sefRelToAbs(YARBB_URL.'&amp;task=viewtopic&amp;id='.$cur_topic['id']).'">'.yarbb_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'._Y_YARBY.' '.yarbb_htmlspecialchars($cur_topic['poster']).'</span>';

										$item_status = 'iclosed';
									}
									if ($cur_topic['last_post'] > $yarbb_user['last_visit'] && !$ghost_topic) {

										$item_status .= ' inew';
										$icon_type = 'icon inew';
										$subject = '<strong>'.$subject.'</strong>';
										$subject_new_posts = '<span class="newtext">&nbsp;<a href="'.sefRelToAbs(YARBB_URL.'&amp;task=viewtopic&amp;id='.$cur_topic['id'].'&amp;action=new').'" title="'._Y_YAGOTONEWTOP.'"><img src="'.$yarbb_live.'/style/images/'.$yarbb_config['o_default_style'].'/folder/folder_new_hot.gif" alt="'._Y_YARNEWPOSTS22.'"/></a>&nbsp;</span>';
									}
									else
										$subject_new_posts = null;
									// We won't display "the dot", but we add the spaces anyway
									if ($yarbb_config['o_show_dot'] == '1')
										$subject = '&nbsp;&nbsp;'.$subject;
									if ($cur_topic['sticky'] == '1') {
										$subject = '<span class="stickytext">'._Y_STICKY.': </span>'.$subject;
										$item_status .= ' isticky';

									}
									$num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / $yarbb_user['disp_posts']);
									if ($num_pages_topic > 1)
										$subject_multipage = '[ '.paginate($num_pages_topic, -1, YARBB_URL.'&amp;task=viewtopic&amp;id='.$cur_topic['id']).' ]';
									else
										$subject_multipage = null;
									// Should we show the "New posts" and/or the multipage links?
									if (!empty($subject_new_posts) || !empty($subject_multipage)) {
										$subject .= '&nbsp; '.(!empty($subject_new_posts) ? $subject_new_posts : '');
										$subject .= !empty($subject_multipage) ? ' '.$subject_multipage : '';
									}
									?>
						<tr<?php if ($item_status != '') echo ' class="'.trim($item_status).'"'; ?>>
							<td class="tcl"><div class="<?php echo $icon_type ?>"> </div>
								<div class="tclcon"> <?php echo $subject."\n" ?> </div></td>
							<td class="tc2"><?php echo (!$ghost_topic) ? $cur_topic['num_replies'] : '&nbsp;' ?></td>
							<td class="tc3"><?php echo (!$ghost_topic) ? $cur_topic['num_views'] : '&nbsp;' ?></td>
							<td class="tcr"><?php echo $last_post ?></td>
							<td class="tcmod"><input type="checkbox" name="topics[<?php echo $cur_topic['id'] ?>]" value="1" /></td>
						</tr>
									<?php
								}
							}
							else {
								$button_status = ' disabled';
								echo "\t\t\t\t\t".'<tr><td class="tcl" colspan="5">'._Y_BANNONE.'</td></tr>'."\n";
							}
							?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
	<div class="linksb">
		<div class="inbox">
			<p class="pagelink conl"><?php echo $paging_links ?></p>
			<p class="conr">
				<input type="submit" name="move_topics" value="<?php echo _Y_YAR_MOVE; ?>"<?php echo $button_status ?> />
				<input type="submit" name="delete_topics" value="<?php echo _E_REMOVE; ?>"<?php echo $button_status ?> />
				<input type="submit" name="open" value="<?php echo _Y_YAROPENTOP; ?>"<?php echo $button_status ?> />
				<input type="submit" name="close" value="<?php echo _Y_YARCLOSETOP; ?>"<?php echo $button_status ?> />
			</p>
			<div class="clearer"></div>
		</div>
	</div>
</form>
	<?php
}